home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 05.zip / BS1 part 5 / IM_Install3.adf / piarc.LZH / NJPLR.rexx < prev    next >
OS/2 REXX Batch file  |  1992-07-11  |  7KB  |  277 lines

  1. /*
  2.  * njplr.rexx
  3.  *
  4.  *  Written by: Pete Patterson
  5.  * Last Update: January 15, 1992
  6.  *         For: Black Belt Systems image processing series IM, IM F/c, and IP.
  7.  * ---------------------------------------------------------------------------
  8.  *    Revision: 1.0
  9.  */
  10.  
  11. /*
  12.  * open rexxsupport.library -- needed for some functions
  13.  */
  14. if ~show('L',"rexxsupport.library") then do
  15.   if addlib('rexxsupport.library',0,-30,0) then do
  16.       /* everything's ok */
  17.     end;
  18.   else do
  19.     say 'We Have A Library Problem, Unable To Load "rexxsupport.library"';
  20.     say 'Cannot operate targar.rexx without this library - sorry!';
  21.     exit 10;
  22.     end;
  23.   end;
  24.  
  25. /*
  26.  * This will automatically direct the script to the proper
  27.  * software, if it is running.
  28.  */
  29. prtnme = 'IP_Port'; /* assume Image Professional */
  30. if show('P','IP_Port') = 0 then do
  31.   if show('P','IM_Port') = 0 then do
  32.     say "Can't find image processor's ARexx port!!!"; /* not running? */
  33.     say "This script requires IP, IM or IM F/c to run!";
  34.     exit(20);
  35.     end;
  36.   else do
  37.     prtnme = 'IM_Port'; /* That's the thing about assumptions... */
  38.     end;                 /* We make em, user's break em.          */
  39.   end;
  40.  
  41. options;
  42. address;
  43.  
  44.   prevpath = 'ram:'; /* put user in ram to start with... */
  45.  
  46.   if show('C',njplpath) = 1 then do
  47.     prevpath = getclip(njplpath);
  48.     end;
  49.  
  50.   address(prtnme);
  51.   options results;
  52.   'current';
  53.   bufdata = result; /* get name of buffer, if there is one */
  54.   parse var bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum;
  55.   if bname ~= '<none>' then do
  56.     bufname = bname;
  57.     end;
  58.   'filerequest "'||prevpath||'","'||bufname||'","","Load NJPL"';
  59.   njplfile = result;
  60.   options;
  61.  
  62.   if njplfile = 'FR_CANCELLED' then do
  63.     address(prtnme);
  64.     'imtofront';
  65.     exit 0;
  66.     end;
  67.  
  68.   njplfile = expandfilename(njplfile);
  69.   thispath = gimmepath(njplfile);
  70.   call setclip(njplpath,thispath);
  71.  
  72.   address command 'cmpi:NJPLRD c "'||njplfile||'"';
  73.   if rc ~= 0 then do
  74.     address(prtnme);
  75.     'message "Cannot read '||njplfile||'"';
  76.     exit 0; /* this is not a proper NJPL file */
  77.     end;
  78.  
  79.   call open(fhandle,'ram:IP_LDNJPL.tmp','read');      /* open the file */
  80.   rstring = readln(fhandle);
  81.   call close(fhandle);                     /* close the file    */
  82.   
  83.   address command 'c:delete >nil: ram:IP_LDNJPL.tmp';
  84.   
  85.   parse var rstring width '/' height
  86.  
  87.   if height < 0 then do
  88.     'message "Bad Height: '||height||'"';
  89.     exit 0;
  90.     end;
  91.  
  92.   if height > 8192 then do
  93.     'message "Bad Height: '||height||'"';
  94.     exit 0;
  95.     end;
  96.  
  97.   if width < 0 then do
  98.     'message "Bad Width: '||width||'"';
  99.     exit 0;
  100.     end;
  101.  
  102.   if width > 8192 then do
  103.     'message "Bad Width: '||width||'"';
  104.     exit 0;
  105.     end;
  106.  
  107.   address(prtnme);
  108.   
  109.   options results;
  110.   'gadgets "Load","'||Width||' by '||Height||'","Half","Size","Quarter","Size","Eight","Size"';
  111.   pxsz = result-1;
  112.   options;
  113.   if pxsz < 0 then do
  114.     address;
  115.     exit 0;
  116.   end
  117.  
  118.   if pxsz = 0 then do
  119.     scl = 1;
  120.   end
  121.  
  122.   if pxsz = 1 then do
  123.     scl = 2;
  124.     width = width / 2;
  125.     height = height / 2;
  126.   end
  127.  
  128.   if pxsz = 2 then do
  129.     scl = 4;
  130.     width = width / 4;
  131.     height = height / 4;
  132.   end
  133.  
  134.   if pxsz = 3 then do
  135.     scl = 8;
  136.     width = width / 8;
  137.     height = height / 8;
  138.   end
  139.  
  140.   'imtofront'; /* show user the IM screen */
  141.   /* is there already a primary buffer??? */
  142.   options results;
  143.   'current';
  144.   bufdata = result;
  145.   options;
  146.  
  147.   mknewbuff = 1;
  148.   parse var bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum
  149.   if bname ~= '<none>' then
  150.     do
  151.       address(prtnme);
  152.       options results;
  153.       mknewbuff = 1;
  154.       'askyn '||'"Replace Primary ['||bname||']" "New As Primary"'
  155.       prefs = result;
  156.       options;
  157.       address;
  158.       if prefs = 0 then
  159.         do
  160.           address(prtnme);
  161.           'killbuff '||bnum; /* this kills the Primary Buffer */
  162.           address;
  163.         end;
  164.     end;
  165.     
  166.   'autoredraw 0';
  167.   if mknewbuff = 1 then do
  168.     /* New buffer is created at current resolution */
  169.     address(prtnme);
  170.     'newbuf '||width||' '||height;
  171.     options results;
  172.     'current';
  173.     bufdata = result;
  174.     options;
  175.     parse var bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum
  176.     if bname = '<none>' then do
  177.       'message "Can`t get buffer."';
  178.       'autoredraw 1';
  179.       exit 0;
  180.     end;
  181.     'rename '||bnum||' 'gxname;
  182.     address;
  183.   end;
  184.  
  185.   address(prtnme);
  186.   options results;
  187.   'askyn '||'"Save Image Info as File" "Don`t Save Image Info"'
  188.   prefs = result;
  189.   options;
  190.   svinfo = 0;
  191.   address;
  192.   
  193.     if prefs = 0 then
  194.     do
  195.       options results;
  196.       'filerequest "'||prevpath||'","'||bufname||'","","Save TEXT"';
  197.       svinfo = 1;
  198.       njplfile2 = result;
  199.       options;
  200.     end;
  201.  
  202.   address(prtnme);
  203.   options results;
  204.   'jackin';
  205.   jackadr = result;
  206.   options;
  207.  
  208.   'wbtofront';
  209.   if (svinfo = 1) then
  210.     do
  211.       address command 'cmpi:NJPLRD d'||jackadr||' "'||njplfile||'" '||scl||' "'||njplfile2||'"';
  212.     end;
  213.   else
  214.     do
  215.       address command 'cmpi:NJPLRD d'||jackadr||' "'||njplfile||'" '||scl;
  216.     end;
  217.  
  218.   address(prtnme);
  219.   'imtofront';
  220.   'redraw';
  221.   'autoredraw 1';
  222.   address;
  223.  
  224.   exit 0;
  225.  
  226. /*
  227.  * gimmepath
  228.  *
  229.  * This takes the provided argument and sucks the path out of it, then
  230.  * returns that path to the caller, sans file name.
  231.  */
  232. gimmepath:
  233.   arg fullnamegx;
  234.     tempgx = reverse(fullnamegx);
  235.     lengx = length(fullnamegx);   /* get length of string */
  236.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  237.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  238.     seploc = 0; /* assumes current dir, no path supplied */
  239.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  240.       seploc = (lengx - slashdex)+1;
  241.       end;
  242.     else do
  243.       if colondex ~= 0 then do /* we assume we are on a device */
  244.         seploc = (lengx - colondex)+1;
  245.         end;
  246.       end;
  247.   gxname = substr(fullnamegx,seploc+1); /* if you ever need it */
  248.   gxpath = left(fullnamegx,seploc);
  249.   return(gxpath);
  250.  
  251. /*
  252.  * Since this script can't be expected to know where the CD of the user
  253.  * is when this cmd is invoked, we have to check the path the user
  254.  * provides - if it's not specified right from a root, then we have
  255.  * to make it a complete specification from the root.
  256.  */
  257. expandfilename:
  258.   parse arg jfile;
  259.   if index(jfile,':') = 0 then do
  260.     curdir = pragma(D);
  261.     if right(curdir,1) ~= ':' then do
  262.       if right(curdir,1) ~= '/' then do
  263.         if curdir ~= '' then do
  264.           curdir = curdir || '/';
  265.           end;
  266.         end;
  267.       end;
  268.     jfile = curdir||jfile;
  269.     end;
  270.   return(jfile);
  271.  
  272. rvalue:
  273.   wordnum = c2d(readch(fhandle,1)) * 256;
  274.   wordnum = wordnum + c2d(readch(fhandle,1));
  275.   return wordnum;
  276.  
  277.